﻿using IBLL;
using IDAL;
using Model;

namespace BLL
{
    public class CardBLL:ICardBLL
    {
        public CardBLL(ICardDAL<Card> dAL)
        {
            DAL = dAL;
        }

        public ICardDAL<Card> DAL { get; }

        public Task<int> CAdd(Card c)
        {
            return DAL.AddAsync(c);
        }

        public Task<int> CDel(int Id)
        {
            var list = DAL.GetAll().FirstOrDefault(x => x.Id == Id);
            list.IsDelete = false;
            return DAL.UpdAsync(list);
        }

        public List<Card> CShow()
        {
            var list =  DAL.GetAll().Where(x => x.IsDelete == true);
            return list.ToList();
        }

        public Task<int> CUpd(Card c)
        {
            return DAL.UpdAsync(c);
        }

        public Card Deng(string Name, string Pass)
        {
            var list = DAL.GetAll().FirstOrDefault(x => x.Name == Name);
            if (list == null)
            {
                return new Card { Id = -1 };
            }
            else
            {
                if (list.Pass != Pass)
                {
                    return new Card { Id = -2 };
                }
                return list;
            }
        }
    }
}
